﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Timer
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void button_start_Click(object sender, EventArgs e)
        {
            timer.Stop();
            timer_sec.Stop();

            decimal time = 0;
            time = numericUpDown_Hrs.Value;
            time = time * 60;
            time = time + numericUpDown_Min.Value;
            time = time * 60;
            time = time + numericUpDown_Sec.Value;
            time = time * 1000;

            timer.Interval = Convert.ToInt32(time);

            label_rest.Text = (timer.Interval/1000).ToString();

            timer_sec.Start();
            timer.Start();

            WindowState = FormWindowState.Minimized;
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            timer_sec.Stop();

            label_rest.Text = "0";
            Show();
            WindowState = FormWindowState.Normal;

            MessageBox.Show("Abgelaufen");
        }

        private void timer_sec_Tick(object sender, EventArgs e)
        {
            int temp = Convert.ToInt32(label_rest.Text);

            label_rest.Text = (temp - 1).ToString();
        }

        private void Main_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                Hide();
            }
        }

        private void notifyIcon_DoubleClick(object sender, EventArgs e)
        {
            Show();
            WindowState = FormWindowState.Normal;
        }
    }
}
